<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles-extras" prefix="tilesx" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<form name="items" method="post" action="">

  <c:forEach items="${adminListCommand.identifier}" varStatus="loopStatus">
  <spring:bind path="adminListCommand.identifier[${loopStatus.index}]">
  <input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}"/>
  </spring:bind>
  </c:forEach>

  <c:set var="numberOfItems" value="${fn:length(items)}"/>
  <c:set var="numberOfColumns" value="${fn:length(columnMessageCodes)}"/>

  <c:forEach begin="1" end="${numberOfColumns}" varStatus="loopStatus">
  <input type="hidden" id="columnWidth_${loopStatus.index - 1}" value="${columnWidths[loopStatus.index - 1]}"/>
  </c:forEach>

  <div style="margin-top:10px;margin-left:10px;margin-right:10px;" align="center" >

      <table class="tableResults" id="myTable" style="padding-bottom:10px;table-layout:fixed;">
      <thead>
        <tr>
          <c:forEach begin="1" end="${numberOfColumns}" varStatus="loopStatus">
          <th id="columnTitle_${loopStatus.index - 1}" style="width:${columnWidths[loopStatus.index - 1]}px;max-width:${columnWidths[loopStatus.index - 1]}px"><spring:message code="${columnMessageCodes[loopStatus.index - 1]}"/></th>
          </c:forEach>
        </tr>
        </thead>
        <c:forEach begin="1" end="${numberOfItems}" varStatus="loopStatus">
        <c:forEach items="${items[loopStatus.index - 1].identifier}" var="innerId" varStatus="idLoopStatus">
        <input type="hidden" id="id_${loopStatus.index-1}_${idLoopStatus.index}" name="id_${loopStatus.index-1}_${idLoopStatus.index}" value="${innerId}"/>
        </c:forEach>

        <c:choose>
        <c:when test="${adminListCommand.canView}">
        <tbody>
        <tr id="item_${loopStatus.index - 1}"
            onclick="viewItem('${loopStatus.index -1}');"
            onMouseOver="javascript:highlightRow('item_${loopStatus.index - 1}', 'roll');"
            onMouseOut="javascript:highlightRow('item_${loopStatus.index - 1}', 'over');">
          <c:forEach begin="1" end="${numberOfColumns}" varStatus="innerLoopStatus">
            <c:set var="tempValue"><c:out value="${items[loopStatus.index - 1].values[innerLoopStatus.index - 1]}"/></c:set>
            <td style="width:${columnWidths[innerLoopStatus.index - 1]}px;max-width:${columnWidths[innerLoopStatus.index - 1]}px" id="columnValue_${loopStatus.index - 1}_${innerLoopStatus.index - 1}">
            <c:choose>
            <c:when test="${tempValue == 'true'}"><img src="pages/images/green_tick.gif" height="15" width="15"/></c:when>
            <c:when test="${tempValue == 'false'}"><img src="pages/images/red_cross.gif" height="15" width="15"/></c:when>
            <c:otherwise>${items[loopStatus.index - 1].values[innerLoopStatus.index - 1]}</c:otherwise>
            </c:choose>
            </td>
          </c:forEach>
        </tr>
        </tbody>
        </c:when>
        <c:otherwise>
        <tbody>
        <tr id="item_${loopStatus.index - 1}">
          <c:forEach begin="1" end="${numberOfColumns}" varStatus="innerLoopStatus">
            <c:set var="tempValue"><c:out value="${items[loopStatus.index - 1].values[innerLoopStatus.index - 1]}"/></c:set>
            <td style="width:${columnWidths[innerLoopStatus.index - 1]}px;max-width:${columnWidths[innerLoopStatus.index - 1]}px" id="columnValue_${loopStatus.index - 1}_${innerLoopStatus.index - 1}">
            <c:choose>
            <c:when test="${tempValue == 'true'}"><img src="pages/images/green_tick.gif" height="15" width="15"/></c:when>
            <c:when test="${tempValue == 'false'}"><img src="pages/images/red_cross.gif" height="15" width="15"/></c:when>
            <c:otherwise>${items[loopStatus.index - 1].values[innerLoopStatus.index - 1]}</c:otherwise>
            </c:choose>
            </td>
          </c:forEach>
        </tr>
        </tbody>
        </c:otherwise>
        </c:choose>
        </c:forEach>
      </table>
  </div>

  <div class="spaced_div" style="padding-bottom:5px;">
    <c:if test="${adminListCommand.canCreateNew}">
    <table align="center">
      <tr>
        <td style="text-align: center;">
          <a class="button_input" onclick="this.blur();newItem();" onmouseover="buttonHover(this);" onmouseout="buttonNormal(this);">
            <span><spring:message code="button.new"/></span>
          </a>
        </td>
      </tr>
    </table>
    </c:if>
  </div>
</form>